package inutan.game.proto;

import inutan.data.MissionGroup.GroupType;
import inutan.game.entity.Achievement;
import inutan.game.entity.MainlineTask;
import inutan.game.entity.Task;
import luban.task.ResCompleteTask;
import luban.task.ResTaskInfo;
import luban.task.TaskInfo;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

/**
 * @Explain --> 任务协议体
 * @Author yanwang
 * @Date 2023/4/3 18:27
 **/
public class TaskProto {

    /**
     * @Explain --> 获得任务信息
     * @Author yanwang
     * @Date 2023/4/3 18:27
     **/
    public static ResTaskInfo getTaskInfo(Optional<MainlineTask> mainTask, List<Task> sideTask) {
        ResTaskInfo resTaskInfo = new ResTaskInfo();
        resTaskInfo.taskList = new ArrayList<>();

        mainTask.ifPresent(vo -> {
            resTaskInfo.taskList.add(taskInfo(vo));
        });

        sideTask.forEach(vo -> {
            resTaskInfo.taskList.add(taskInfo(vo));
        });
        return resTaskInfo;
    }


    /**
    * @Explain --> 获得成就信息
    * @Author yanwang
    * @Date 2023/5/19 13:34
    **/
    public static ResTaskInfo getTaskInfo(List<Achievement> achievement) {
        ResTaskInfo resTaskInfo = new ResTaskInfo();
        resTaskInfo.taskList = new ArrayList<>();
        achievement.forEach(vo -> {
            resTaskInfo.taskList.add(taskInfo(vo));
        });
        return resTaskInfo;
    }

    public static TaskInfo taskInfo(Task side) {
        TaskInfo vo = new TaskInfo();
        vo.id = side.getId();
        vo.taskId = side.getTaskId();
        vo.taskType = side.getTaskType();
        vo.progress = side.getProgress().values().stream().findFirst().orElse(0);
        vo.status = side.getState();
        return vo;
    }

    public static TaskInfo taskInfo(MainlineTask main) {
        TaskInfo vo = new TaskInfo();
        vo.id = main.getId();
        vo.taskId = main.getTaskId();
        vo.taskType = GroupType.MainMission;
        vo.progress = main.getProgress().values().stream().findFirst().orElse(0);
        vo.status = main.getState();
        return vo;
    }

    public static TaskInfo taskInfo(Achievement achievement) {
        TaskInfo vo = new TaskInfo();
        vo.id = achievement.getId();
        vo.taskId = achievement.getTaskId();
        vo.taskType = GroupType.AchieveMission;
        vo.progress = achievement.getProgress().values().stream().findFirst().orElse(0);
        vo.status = achievement.getState();
        return vo;
    }


    public static ResCompleteTask getCompleteTask(int taskId, List<TaskInfo> newTaskList) {
        ResCompleteTask resCompleteTask = new ResCompleteTask();
        resCompleteTask.taskId = taskId;
        resCompleteTask.addTaskList = new ArrayList<>();
        resCompleteTask.addTaskList.addAll(newTaskList);
        return resCompleteTask;
    }

}
